package com.kws.system.api.factory;

import com.kws.common.core.domain.R;
import com.kws.system.api.RemotePaymentService;
import com.kws.system.api.domain.Rq.AlipayRefundOrderRq;
import com.kws.system.api.domain.Rq.AlipayWebRq;
import com.kws.system.api.domain.Rq.CreateWeixinPayOrderRq;
import com.kws.system.api.domain.Rq.WeixinPayRefundRq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author : zhangbenting
 * @date : 2024/11/26 13:41
 * @Version: 1.0
 */
@Component
public class RemotePaymentFallbackFactory implements FallbackFactory<RemotePaymentService> {
    private static final Logger log = LoggerFactory.getLogger(RemotePaymentFallbackFactory.class);

    @Override
    public RemotePaymentService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemotePaymentService() {
            @Override
            public R createWeixinWebPayOrder(CreateWeixinPayOrderRq rq) {
                return R.fail("web端微信支付-下单:" + throwable.getMessage());
            }

            @Override
            public R createWeixinH5PayOrder(CreateWeixinPayOrderRq rq) {
                return R.fail("H5端微信支付-下单:" + throwable.getMessage());
            }

            @Override
            public R closeWeixinWebPayOrder(String orderNo) {
                return R.fail("web端微信支付-关闭订单:" + throwable.getMessage());
            }

            @Override
            public R closeWeixinH5PayOrder(String orderNo) {
                return R.fail("H5端微信支付-关闭订单:" + throwable.getMessage());
            }

            @Override
            public R weixinPayRefundOrder(WeixinPayRefundRq rq) {
                return R.fail("微信支付退款申请:" + throwable.getMessage());
            }

            @Override
            public R alipayWebOrder(AlipayWebRq rq) {
                return R.fail("支付宝web端下单拉起支付:" + throwable.getMessage());
            }

            @Override
            public R cancelAlipayOrder(String orderNo) {
                return R.fail("取消支付订单:" + throwable.getMessage());
            }

            @Override
            public R refundOrder(AlipayRefundOrderRq rq) {
                return R.fail("根据订单号进行退单退款:" + throwable.getMessage());
            }
        };
    }
}
